package com.qiuzhiyi.dialogs;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AlertDialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.qiuzhiyi.R;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Author: Li
 * Date: 2017/11/15 0015
 * Description: 分享界面
 */

public class DialogShare {

    private OnBoardItemClickListener mItemClickListener;
    private AlertDialog mDialog;

    public DialogShare(Context context, OnBoardItemClickListener itemClickListener) {
        mItemClickListener = itemClickListener;
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        View view = layoutInflater.inflate(R.layout.layout_pop_share, null);
        AlertDialog.Builder builder = new AlertDialog.Builder(context)
                .setView(view);
        ButterKnife.bind(this, view);
        mDialog = builder.create();
    }

    public void show() {
        mDialog.show();
        Window window = mDialog.getWindow();
        if (window == null) {
            return;
        }
        window.setWindowAnimations(R.style.PopAnimStyle);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        params.gravity = Gravity.BOTTOM;
        window.setAttributes(params);
    }

    @OnClick({R.id.layout_board, R.id.txt_lianjie, R.id.txt_erweima,
            R.id.txt_qq, R.id.txt_qq_zone, R.id.txt_weixin,
            R.id.txt_pengyouquan, R.id.txt_weibo, R.id.txt_cancel})
    public void onViewClicked(View view) {
        mDialog.dismiss();
        switch (view.getId()) {

            case R.id.layout_board:
                break;
            case R.id.txt_cancel:
                break;
            default:
                mItemClickListener.onBoardItemClick(view, view.getTag().toString());
                break;
        }
    }

    public interface OnBoardItemClickListener {
        void onBoardItemClick(View view, String tag);
    }
}
